package com.xi.jetcomposedemo.ui.compose

import androidx.activity.ComponentActivity
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.dp
import com.xi.jetcomposedemo.ui.theme.JetComposeDemoTheme

@Composable
fun isPortrait(): Boolean {
    return LocalConfiguration.current.orientation == android.content.res.Configuration.ORIENTATION_PORTRAIT
}

@Composable
fun ComponentActivity.AppSkeleton(
    showTitleBar: Boolean = true,
    content: @Composable ColumnScope.() -> Unit,
) {
    JetComposeDemoTheme {
        Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
            Column(Modifier.fillMaxSize()) {
                if (showTitleBar) {
                    Box(
                        Modifier
                            .height(45.dp)
                            .clickable {
                                finish()
                            }, contentAlignment = Alignment.Center
                    ) {
                        Text(
                            text = "返回", modifier = Modifier.padding(start = 12.dp)
                        )
                    }
                }
                content()
            }
        }
    }
}